<?php

namespace App\Pool\Redis;


use Illuminate\Foundation\Application;
use Swoole\Database\RedisConfig;
use Swoole\Database\RedisPool as Pool;

class RedisPool
{
    protected $app;

    protected $pool;

    public function __construct(Application $app)
    {
        $this->app = $app;
        $this->init();
    }

    protected function init()
    {
        $config = (new RedisConfig)
            ->withHost(env('REDIS_HOST', '127.0.0.1'))
            ->withPort(env('REDIS_PORT', 6379))
            ->withAuth(env('REDIS_PASSWORD', '') ?? '');

        $this->pool = new Pool($config, env('REDIS_SIZE', 20));
    }

    public function get()
    {
        return $this->pool->get();
    }

    public function put($pdo)
    {
        $this->pool->put($pdo);
    }
}